package com.djinfo.work.dao.impl;

import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.DictionariesDao;
import com.djinfo.work.entity.DicVo;
import com.djinfo.work.entity.Dictionaries;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by admin on 2017/5/18.
 */
@Repository("DictionariesDao")
public class DictionariesDaoImpl extends BaseDaoImpl implements DictionariesDao {

    @Override
    public void save(Dictionaries object) {
        if (object.getId() == null) {
            super.save(object);
        } else {
            super.update(object);
        }
    }

    @Override
    public void update(Dictionaries object) {
        super.update(object);
    }

    @Override
    public void delete(Dictionaries object) {
        Dictionaries tbDicNotice1 = (Dictionaries)super.getByPrimaryKey(Dictionaries.class,object.getId());
        super.delete(tbDicNotice1);
    }

    @Override
    public Dictionaries getDictionariesById(String id) {
        return (Dictionaries)super.get(Dictionaries.class,id);
    }

    @Override
    public List<Dictionaries> page(Dictionaries object, Integer pageNum, Integer pageSize) {
        String hql="";
        if(object.getName()==""||object.getName()==null){
            hql = " from Dictionaries where 1=1 ";
        }else {
            hql = " from Dictionaries where name like '%"+ object.getName()+ "%'";
        }
        return (List<Dictionaries>)super.pageQuery( hql,  pageNum,  pageSize);
    }

    @Override
    public List<Dictionaries> list() {
        String hql = " from Dictionaries where 1=1 ";
        return (List<Dictionaries>)super.getList(hql);
    }

    @Override
    public Integer getAllRowCount(Dictionaries dictionaries) {
        String hql="";
        if(dictionaries.getName()==""||dictionaries.getName()==null){
            hql = "select count(*) from Dictionaries ";
        }else {
            hql = "select count(*) from Dictionaries where name like '%"+ dictionaries.getName()+ "%'";
        }
        return super.getUniqueObject(hql).hashCode();
    }

    @Override
    public List<Dictionaries> messagesTypeList(String type) {
        String hql = "from Dictionaries where type='"+type+"'";
        return (List<Dictionaries>)super.getList(hql);
    }

    @Override
    public List<Dictionaries> messagesStatusList(String type) {
        String hql = "from Dictionaries where type='"+type+"'";
        return (List<Dictionaries>)super.getList(hql);
    }

    @Override
    public List<Dictionaries> processTypeList(String type) {
        String hql = "from Dictionaries where type='"+type+"'";
        return (List<Dictionaries>)super.getList(hql);
    }

    @Override
    public List<DicVo> getDic(String dic) {
        String hql = "select new com.djinfo.work.entity.DicVo(d.name,d.code) from Dictionaries d where type=?";
        return (List<DicVo>)super.getList(hql,dic);
    }
}
